X-Git-Url: https://git.r.bdr.sh/rbdr/super-polarity/blobdiff_plain/d0950076b4ac797578bc4286a9f631196b4c00c7..bca44639c27169b0643de1b56361e6c2958d1d4a:/Super%20Polarity/NameChooserWidget.cs diff --git a/Super Polarity/NameChooserWidget.cs b/Super Polarity/NameChooserWidget.cs new file mode 100644 index 0000000..ce7c149 --- /dev/null +++ b/Super Polarity/NameChooserWidget.cs @@ -0,0 +1,99 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +namespace SuperPolarity +{ + class NameChooserWidget : Widget + { + int CurrentIndex; + bool Lock; + int LockRate; + int CurrentTime; + + public NameChooserWidget(SuperPolarity game, Vector2 position) + : base(game, position) + { + AppendChild(new LetterChooseWidget(game, new Vector2(position.X, position.Y))); + AppendChild(new LetterChooseWidget(game, new Vector2(position.X + 32, position.Y))); + AppendChild(new LetterChooseWidget(game, new Vector2(position.X + 64, position.Y))); + CurrentIndex = 0; + Children[CurrentIndex].Activate(); + LockRate = 300; + CurrentTime = 0; + + InputController.Bind("moveX", HandleMovement); + } + + public override void Update(GameTime gameTime) + { + base.Update(gameTime); + + CurrentTime = CurrentTime + gameTime.ElapsedGameTime.Milliseconds; + if (CurrentTime > LockRate) + { + CurrentTime = 0; + Lock = false; + } + + foreach (LetterChooseWidget widget in Children) + { + widget.Update(gameTime); + } + } + + public void HandleMovement(float value) + { + if (value > 0.8 && !Lock) + { + Children[CurrentIndex].Deactivate(); + CurrentIndex = CurrentIndex + 1; + + if (CurrentIndex > Children.Count - 1) + { + CurrentIndex = 0; + } + + Lock = true; + } + + if (value < -0.8 && !Lock) + { + Children[CurrentIndex].Deactivate(); + CurrentIndex = CurrentIndex - 1; + + if (CurrentIndex < 0) + { + CurrentIndex = Children.Count - 1; + } + + Lock = true; + } + + Children[CurrentIndex].Activate(); + } + + public string Value() + { + var name = ""; + + foreach (LetterChooseWidget letter in Children) + { + name = name + letter.Value(); + } + + return name; + } + + public override void Draw(SpriteBatch spriteBatch) + { + foreach (LetterChooseWidget widget in Children) + { + widget.Draw(spriteBatch); + } + } + } +}